//
//  HLHomeHeardView.swift
//  RxSwiftMoya
//
//  Created by hulinhu on 2018/1/22.
//  Copyright © 2018年 hulinhu. All rights reserved.

//  头部视图

import UIKit
import Then
import SnapKit
import RxSwift
import RxGesture
import RxCocoa

// MARK:- 常量
fileprivate struct Metric {
    
    static let heardWidth: CGFloat =  kScreenWidth
    static let heardHeight: CGFloat = 44.0
}

class HLHomeHeardView: UIView {
    
    
    var bag : DisposeBag = DisposeBag()

    typealias AddBlock = ( _ index : NSInteger )->Void;
    var itemClicked: AddBlock? = { (_) in
        return
    }
    
    // 初始化变量
    let bgView = UIView().then { (bgView) in
        bgView.backgroundColor = UIColor.yellow
        bgView.frame = CGRect.init(x: 0, y: 0, width: kScreenWidth, height: 44)
    }
    
    
    // 重新系统方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.rx.tapGesture().when(.recognized).subscribe { (_) in
            self.itemClicked!(100)
        }.disposed(by: bag)
        self.addSubview(bgView)
    }
    
    
    // 重新自定义方法
//    init(frame: CGRect, itemClicked:@escaping AddBlock) {
//        super.init(frame: frame)
//        self.rx.tapGesture().when(.recognized).subscribe { (_) in
//            itemClicked(100)
//        }.disposed(by: bag)
//        self.addSubview(bgView)
//    }
    
    // 遍历构造
    convenience init(frame: CGRect , itemClicked:@escaping AddBlock) {
        self.init(frame:frame)
        self.rx.tapGesture().when(.recognized).subscribe { (_) in
            itemClicked(100)
        }.disposed(by: bag)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.snp.makeConstraints { (make) in
            make.width.equalTo(Metric.heardWidth)
            make.height.equalTo(Metric.heardHeight)
        }
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
}

extension HLHomeHeardView {
    
    
}


